package com.aptemo.webetek.server.handlers;

import java.util.ArrayList;

import com.aptemo.webetek.client.commands.Action;
import com.aptemo.webetek.client.commands.impl.GetPlayersAction;
import com.aptemo.webetek.client.commands.responses.ListResponse;
import com.aptemo.webetek.client.exceptions.BackendException;
import com.aptemo.webetek.client.exceptions.WebetekLoginException;
import com.aptemo.webetek.server.datastore.DataStoreAPI;
import com.aptemo.webetek.shared.UserBean;

public class PlayersHandler
		extends ActionHandler<GetPlayersAction, ListResponse<UserBean>>
{

	public PlayersHandler(DataStoreAPI service)
	{
		super(service);
	}

	public Class<? extends Action<?>> getActionType()
	{
		return GetPlayersAction.class;
	}

	@Override
	public ListResponse<UserBean> invoke(GetPlayersAction action) throws BackendException, WebetekLoginException
	{
		utils.checkLogin();

		ArrayList<UserBean> result = (ArrayList<UserBean>) dataService.getPlayers(action.getTeamId(), action.getStatus(), action.getOrder());
		return new ListResponse<UserBean>(result);
	}

}
